package com.design_patterns.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 李德才
 * @description:
 * @create: 2020-09-20 19:56
 **/
public class IThink {

    public static void main(String[] args) {
        Child child = new Child();
        child.setObServe(new Dad()).setObServe(new Mum()).setObServe(new Dog());
        child.weekUp();

        /**
         * 问题是狗只能叫，爸爸只能喂，妈妈只能抱抱
         */
    }
    static class People {
        private String name;
        private Main2.WakeUpEvent wakeUpEvent;

        public Main2.WakeUpEvent getWakeUpEvent() {
            return wakeUpEvent;
        }

        public String getName() {
            return name;
        }
    }

    static class Dad implements ObServer {
        @Override
        public void actionOnWakeUp(People people) {
            System.err.println("给吃的");
        }
    }

    static class Mum implements ObServer {

        @Override
        public void actionOnWakeUp(People people) {
            System.err.println("抱抱");
        }
    }

    static class Dog implements ObServer {

        @Override
        public void actionOnWakeUp(People people) {
            System.err.println(" wang wang wang 。。。 。。。");
        }
    }

    static class Child extends People {
        private boolean cry = false;
        private List<ObServer> obServerList = new ArrayList<>();

        public Child setObServe(ObServer obServe) {
            this.obServerList.add(obServe);
            return this;
        }

        //        醒了要哭
        public void weekUp() {
            System.err.println(" I'm crying");
//            处理方法集合
            obServerList.forEach(obServer -> {
                obServer.actionOnWakeUp(this);
            });
        }
    }

    interface ObServer {
        void actionOnWakeUp(People people);
    }
}